import {Switch,Route,Redirect} from 'react-router-dom'
function View({routes}){
    if(!routes){
        return null
    }
    let router=routes.filter(item=>!item.to)
    let redirect=routes.filter(item=>item.to).map((item1,index)=><Redirect from={item1.path} to={item1.to} key={index} />)
    return<Switch>
        {
            router.map((item,index)=>{
                return<Route 
                    path={item.path}
                    key={index}
                    render={props=>{
                        return <item.component {...props} routes={item.children} />
                    }}
                />
            }).concat(redirect)
        }
    </Switch>
}
export default View